<!-- src/components/FileIconView.vue -->
<template>
    <a-list v-if="viewMode === 'IconView'" :data-source="filteredFiles"
        :grid="{ gutter: 16, xs: 1, sm: 2, md: 3, lg: 4, xl: 6, xxl: 8 }">
        <template #renderItem="{ item }">
            <a-list-item>
                <a-dropdown :trigger="['contextmenu']">
                    <div @contextmenu.stop>
                        <div class="file-item" :data-id="item.id"
                            :class="{ 'file-item-selected': selectedFiles.includes(item.id) }"
                            @click="handleFileClick(item, $event)">
                            <div class="file-icon">
                                <img :src="getFileIcon(item.type)" :alt="item.type" />
                            </div>
                            <div class="file-info">
                                <div class="file-name">{{ item.name }}</div>
                            </div>
                        </div>
                    </div>
                    <template #overlay>
                        <a-menu>
                            <a-menu-item key="1">下载</a-menu-item>
                            <a-menu-item key="2">重命名</a-menu-item>
                            <a-menu-item key="3" @click="showFileProperties(item)">属性</a-menu-item>
                            <a-menu-divider />
                            <a-menu-item key="4">删除</a-menu-item>
                        </a-menu>
                    </template>
                </a-dropdown>
            </a-list-item>
        </template>
    </a-list>
</template>

<script>
export default {
    name: 'FileIconView',
    props: {
        filteredFiles: {
            type: Array,
            required: true
        },
        selectedFiles: {
            type: Array,
            required: true
        },
        viewMode: {
            type: String,
            default: 'IconView'
        },
        getFileIcon: {
            type: Function,
            required: true
        },
        handleFileClick: {
            type: Function,
            required: true
        },
        showFileProperties: {
            type: Function,
            required: true
        }
    }
};
</script>

<style scoped>
.file-item {
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    border: 2px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    background: #ffffff;
    position: relative;
    overflow: hidden;
    user-select: none;
}

.file-item:hover {
    border-color: #d9d9d9;
    background: linear-gradient(135deg, #fafafa 0%, #f5f5f5 100%);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
}

.file-item:hover .file-icon img {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.file-item-selected {
    border-color: #1890ff !important;
    background: linear-gradient(135deg, #e6f7ff 0%, #f0f9ff 100%) !important;
    box-shadow:
        0 0 0 2px rgba(24, 144, 255, 0.2),
        0 4px 16px rgba(24, 144, 255, 0.15),
        0 2px 6px rgba(24, 144, 255, 0.1) !important;
    transform: translateY(-2px) !important;
}

.file-icon img {
    width: 64px;
    height: 64px;
    margin-bottom: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}
</style>